unit uFrmPessoaImp;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, uFrmBaseImp, frxExportRTF, frxExportXML, frxExportXLS,
  frxExportHTML, frxClass, frxExportPDF, frxDBSet, StdCtrls, JvExStdCtrls,
  JvButton, JvCtrls, JvFooter, ExtCtrls, JvExExtCtrls, JvExtComponent,
  Telesis_EditEnh, frxExportCSV, frxExportText, frxExportImage, frxChBox;

type
  TFrmPessoaImp = class(TFrmBaseImp)
    rgTipoRel: TRadioGroup;
    txtCodigo: TEditEnh;
    Label1: TLabel;
    txtNome: TEditEnh;
    rgOrdenacao: TRadioGroup;
    frxReportA: TfrxReport;
    procedure txtCodigoButton1(Sender: TObject);
    procedure txtCodigoEnter(Sender: TObject);
    procedure txtCodigoExit(Sender: TObject);
    procedure btnImprimirClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FrmPessoaImp: TFrmPessoaImp;

implementation

uses
  Rot_Utilidade, uDMGeral;

{$R *.dfm}

procedure TFrmPessoaImp.txtCodigoButton1(Sender: TObject);
begin
  inherited;
  txtCodigo.Text := Procura(DMGeral.qPessoa, 'PESSOACODIGO');
end;

procedure TFrmPessoaImp.txtCodigoEnter(Sender: TObject);
begin
  inherited;
  vAnt := -1;
end;

procedure TFrmPessoaImp.txtCodigoExit(Sender: TObject);
begin
  inherited;
  ValidaInteiroExit(DMGeral.qPessoa_Local, vAnt, ['PESSOANOME'],['CODIGO'],[txtCodigo],[txtNome]);
end;

procedure TFrmPessoaImp.btnImprimirClick(Sender: TObject);
var vWhere : Boolean;
begin
  inherited;
  vWhere := False;
  case rgTipoRel.ItemIndex of
    0 : begin
       DMGeral.qPessoaImpA.SQL[32] := '';
       DMGeral.qPessoaImpA.SQL[33] := '';

       if StrToInt(txtCodigo.Text) > 0 then
         DMGeral.qPessoaImpA.SQL[32] := WhereAnd(vWhere) + ' P.PESSOACODIGO = ' + txtCodigo.Text;

       case rgOrdenacao.ItemIndex of
         0 : DMGeral.qPessoaImpA.SQL[33] := 'ORDER BY P.PESSOACODIGO';
         1 : DMGeral.qPessoaImpA.SQL[33] := 'ORDER BY P.PESSOANOME';
       end;

       LoadReport(frxReportA, DMGeral.qPessoaImpA);
    end;
    1 : begin
       DMGeral.qPessoaImpS.SQL[23] := '';
       DMGeral.qPessoaImpS.SQL[24] := '';

       if StrToInt(txtCodigo.Text) > 0 then
         DMGeral.qPessoaImpS.SQL[23] := WhereAnd(vWhere) + ' P.PESSOACODIGO = ' + txtCodigo.Text;

       case rgOrdenacao.ItemIndex of
         0 : DMGeral.qPessoaImpS.SQL[24] := 'ORDER BY P.PESSOACODIGO';
         1 : DMGeral.qPessoaImpS.SQL[24] := 'ORDER BY P.PESSOANOME';
       end;

       LoadReport(frxReport, DMGeral.qPessoaImpS);
    end;
  end;
end;

end.
